<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>方案列表页面</title>
    <script src="../../res/js/jquery-3.4.1.min.js"></script>
    <script src="../../res/layui/layui.js" charset="utf-8" media="all"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script src="../../res/js/login_common.js" type="text/javascript" charset="utf-8"></script>

    <script>
        $(function(){
            $("#btn").on("click",function(){
                //执行重载
                //带条件查询
                table2.reload({
                    url: '../../AtsSchemeAction/findAllkangfu',
                    where: {
                        name: $("#keyword").val(),
                        userid:loginObj.manager.usWaiid,
                        type:loginObj.manager.usType
                    },
                        page: { curr:1}
                });
            })
            finByCoach();
        });
    </script>
</head>
    <body>



    <script type="text/javascript">
    $.ajaxSetup({
        async:false
    })
    </script>

  <!--  <div class="layui-input-inline">
        <input type="text" name="keyword" id="keyword" lay-verify="required" placeholder="请输入方案名" autocomplete="off" class="layui-input">
    </div>
        <button type="button" id="btn" class="layui-btn layui-btn-radius layui-btn-warm">搜索</button>-->
    <div style="height: 10px"></div>
    <div class="layui-inline">
        <label class="layui-form-label" style="width:85px;">方案名</label>
        <div class="layui-input-inline">
            <input type="text" placeholder="请输入方案名" id="schemeName" class="layui-input" style="width:200px;float:left;height:32px;">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label" style="width:90px;">方案日期</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="startTime" autocomplete="off" name="startTime" placeholder="请输入开始时间" style="width:200px;float:left;height:32px;">
            <span style="float:left;">—</span>
            <input type="text" class="layui-input" id="endTime" name="endTime" autocomplete="off"  placeholder="请输入结束时间" style="width:200px;float:left;height:32px;">
        </div>
    </div>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" id="search" style="margin-left: 10px;">搜索</button>

    <input id="coachId" name="coachId" hidden></input>
    <table class="layui-hide" id="test" lay-filter="test"></table>

    <script type="text/html" id="barDemo">
        <!--判断用户权限-->
        <a class="layui-btn layui-btn-xs layui-bg-gray" lay-event="look">查看</a>
        <button type="button" class="layui-btn layui-btn-xs layui-bg-cyan" lay-event="export">导出方案</button>
        {{#if(loginObj.manager.usType=='运动员'){ }}

        {{# } else if(loginObj.manager.usType=='领导'){ }}
            {{# if(d.auditState==10||d.auditState==0){ }}
                <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event="audit">审核</button>
            {{# } else{ }}
                <a type="button" class="layui-btn layui-btn-xs layui-btn-normal layui-btn-disabled" disabled="true">审核</a>
            {{# } }}
        {{# } else if(loginObj.manager.usType=='教练'){ }}
            <!--判断方案提交状态-->
            {{#if(d.auditState==0||d.auditState==21){ }}
                <button type="button" class="layui-btn layui-btn-xs layui-btn-normal"  lay-event="sub">提交审核</button>
                <button type="button" class="layui-btn layui-btn-xs"  lay-event="edit">编辑</button>
                <button type="button" class="layui-btn layui-btn-xs layui-bg-red" lay-event="del">删除</button>
            {{# } else if(d.auditState==20){ }}
                <button type="button" class="layui-btn layui-btn-xs layui-bg-orange"  lay-event="consult">专家咨询</button>
                <button type="button" class="layui-btn layui-btn-xs"  lay-event="edit">编辑</button>
            {{# } else if(d.auditState==40){ }}
                <button type="button" class="layui-btn layui-btn-xs"  lay-event="edit">编辑</button>
                <button type="button" class="layui-btn layui-btn-xs layui-bg-orange" lay-event="feedback">反馈</button>
                <button type="button" class="layui-btn layui-btn-xs layui-bg-red" lay-event="del">删除</button>
        {{# } else { }}
             <!--   <button type="button" class="layui-btn layui-btn-xs layui-btn-normal layui-btn-disabled" disabled ="true"lay-event="sub">提交审核</button>
                <button type="button" class="lay

                ui-btn layui-btn-xs layui-btn-disabled" disabled ="true">编辑</button>
                <button type="button" class="layui-btn layui-btn-xs layui-btn-disabled" disabled ="true">删除</button>-->
            {{# } }}
        {{# } else if(loginObj.manager.usType=='专家'){ }}
            {{#if(d.auditState==20){ }}
                <button type="button" class="layui-btn layui-btn-xs" lay-event="reply">回复咨询</button>
            {{# } }}
        {{# } }}
    </script>
    <script type="text/html" id="file1">
        {{#if(d.file1!=null){ }}
            <a href="../..{{d.file1}}" class="layui-btn layui-btn-xs">下载</a>
        {{# }else{ }}
            <span>无文件</span>
        {{# } }}
    </script>
    <script type="text/html" id="file2">
        {{#if(d.file2!=null){ }}
            <a href="../..{{d.file2}}" class="layui-btn layui-btn-xs">下载</a>
        {{# }else{ }}
            <span>无文件</span>
        {{# } }}
    </script>
    <script type="text/html" id="file3">
        {{#if(d.file3!=null){ }}
            <a href="../..{{d.file3}}" class="layui-btn layui-btn-xs">下载</a>
        {{# }else{ }}
            <span>无文件</span>
        {{# } }}
    </script>
    <script type="text/html" id="resultFile">
        {{#if(d.resultFile!=null){ }}
            <a href="../..{{d.resultFile}}" class="layui-btn layui-btn-xs">下载</a>
        {{# }else{ }}
            <span>无文件</span>
        {{# } }}
    </script>
    <script type="text/javascript" charset="utf-8">
        var table2=null;

        layui.use(['table','laydate'], function(){
            var laydate = layui.laydate;
            var table = layui.table;
            table2=table.render({
                elem: '#test'
                ,url:'../../AtsSchemeAction/findAllkangfu?userid='+loginObj.manager.usWaiid+"&type="+loginObj.manager.usType
                ,toolbar: '#toolbarDemo'
                ,toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                ,page: true //开启分页
                ,title: '方案表'
                ,cols: [[
                     {type:'checkbox'}
                    ,{field:'schemeId', title:'ID', width:60}
                    ,{field:'coachName', title:'教练姓名', width:100}
                    ,{field:'schemeName', title:'方案名称', width:105}
                    ,{field:'resultExp', title:'实施情况', width:104, sort: true}
                    ,{field:'resultEffect', title:'实施效果', width:104, sort: true}
                    ,{field:'resultTime', title:'反馈时间', width:104, sort: true}
                    ,{field:'resultEffect', title:'实施效果', width:104, sort: true}
                    ,{field:'file1', title:'文件一', width:104, sort: true,toolbar: '#file1'}
                    ,{field:'resultFile', title:'实施附件', width:104, sort: true,toolbar: '#resultFile'}
                    ,{fixed:'right', title:'操作', toolbar: '#barDemo', width:305}
                ]]
                ,page: true
        });
            //执行一个laydate实例
            laydate.render({
                elem: '#startTime' //指定元素
            });
            laydate.render({
                elem: '#endTime' //指定元素
            });
            /* 头部工具栏监听 */
            table.on('toolbar(test)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id)
                    ,data = checkStatus.data; //获取选中的数据
                if(loginObj.manager.usType!='运动员'&&loginObj.manager.usType!='领导'&&loginObj.manager.usType!='专家'){
                    switch(obj.event){
                        case 'add':
                            //iframe层
                            layer.open({
                                type: 2,
                                title: '新增页面',
                                shadeClose: true,
                                shade: 0.8,
                                area: ['65%', '80%'],
                                content: 'AtsSchemeAddorUpdate.html', //iframe的url
                                end:function(){
                                    table2.reload();
                                }
                            });
                            break;
                        case 'delete':
                            if(data.length === 0){
                                layer.msg('请选择一行');
                            } else {
                                if(confirm("确定需要删除吗?")){
                                    var ids = "";
                                    $.each(data,function(index,item){
                                        ids+=item.schemeId+",";
                                    })
                                    var url = "../../AtsSchemeAction/updatestateall";
                                    var data ={ids:ids};
                                    $.post(url,data,function(obj){
                                        if(obj.state!=0){
                                            window.location.reload();
                                        }else{
                                            alert("删除失败!");
                                        }
                                    })
                                }
                            }
                            break;
                    }
                }

            });

            table.on('tool(test)', function(obj){
                var data = obj.data;
                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        obj.del();
                        layer.close(index);
                        var url="../../AtsSchemeAction/updatestate";
                        var dataone={"id":data.schemeId};
                        $.post(url,dataone,function(obj){
                            if(obj.num==1){
                                layer.msg(obj.msg,{
                                    icon:1,
                                    time:1000 //1秒关闭(如果不配置默认三秒)
                                },function(){
                                    //刷新父页面
                                    parent.location.reload();
                                });
                            }else{
                                layer.msg(obj.msg);
                            }
                        },"json")
                    });
                }else if(obj.event === 'edit'){
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '编辑',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['65%', '80%'],
                        content: 'AtsSchemeAddorUpdate.html?id='+data.schemeId, //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                }else if(obj.event === 'sub'){
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '申请',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['60%', '50%'],
                        content: 'AtsSchemeSubmit.html?id='+data.schemeId, //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                }else if(obj.event === 'look'){
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '查看',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['80%', '70%'],
                        content: 'AtsSchemeMessage.html?id='+data.schemeId, //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                }else if(obj.event === 'feedback'){
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '反馈',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['60%', '90%'],
                        content: 'AtsSchemefeedback.html?id='+data.schemeId, //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                }else if(obj.event === 'audit'){
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '审核',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['60%', '97%'],
                        content: 'AtsSchemeAudit.html?id='+data.schemeId+"&name="+data.schemeName, //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                }else if(obj.event==='consult'){
                    layer.confirm('确定申请专家咨询', function(index){
                        layer.close(index);
                        var url="../../ase/updateSchemeExpert";
                        var dataone={"id":data.schemeId};
                        $.post(url,dataone,function(obj){
                            if(obj.num==1){
                                layer.msg(obj.msg,{
                                    icon:1,
                                    time:1000 //1秒关闭(如果不配置默认三秒)
                                },function(){
                                    //刷新父页面
                                    parent.location.reload();
                                });
                            }else{
                                layer.msg(obj.msg);
                            }
                        },"json")
                    });
                }if(obj.event === 'reply'){
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '回复页面',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['43%', '97%'],
                        content: 'AtsSchemeConsultation.html?id='+data.schemeId+"&name="+data.schemeName, //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                }if(obj.event === 'export'){
                    layer.confirm('是否导出文件？', function(index){
                       window.open("../../AtsSchemeAction/FileExpert?id="+data.schemeId);
                       layer.close(index);
                    });
                }
            });
        });
        /* 教练员赋值*/
        function finByCoach() {
            if(loginObj.manager.usType=="教练员"){
                $("#coachId").val(loginObj.manager.usWaiid);
            }
        }
    </script>

</body>
</html>